The foundation of a flexible system lies in defining a rigid internal contract or interface that objects must follow. In this context, we define a Table Interface where every cell object guarantees the existence of three specific methods: minWidth(), minHeight(), and draw(width, height).
1. The Interface Contract
By standardizing on these methods, the layout logic can calculate global row and column dimensions without knowing the internal data types of individual cells. This is a classic example of Interface-based Polymorphism.
2. TextCell Implementation
The TextCell constructor prepares raw input by splitting strings into line-by-line arrays. This shifts complexity from the rendering phase to the instantiation phase.
3. Deterministic Drawing
The draw(width, height) method ensures that every cell output is perfectly padded using a repeat() helper. This maintains vertical and horizontal alignment regardless of content length.
$$\text{Padding} = \text{Width} - \text{line.length}$$